﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZhouYu.NewWorld.BLL.IService;
using ZhouYu.NewWorld.Model;
using ZhouYu.NewWorld.ViewModel;

namespace ZhouYu.NewWorld.Web.Controllers
{
    public class CashnumberController : Controller
    {
        //注入
        private ICashnumberService _cashnumberService;
        public CashnumberController(ICashnumberService cashnumberService)
        {
            _cashnumberService = cashnumberService;
        }
        
        // GET: Cashnumber
        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 多表查询
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public JsonResult CashnuumberInfo(int page, int limit) 
        {
            ResponseResult result = _cashnumberService.CashnumberInfo(page, limit);
            return Json(result,JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 添加一条数据
        /// </summary>
        /// <param name="cashnumber"></param>
        /// <returns></returns>
        public JsonResult AddCashnumber(Cashnumber cashnumber) 
        {
            ResponseResult result = new ResponseResult();
            cashnumber.Cash_freeze = 0;
            cashnumber.Cash_UpdateTime = DateTime.Now;
            cashnumber.Cash_CreateTime = DateTime.Now;
            result.Success = _cashnumberService.Add(cashnumber);
            return Json(result);
        }

        /// <summary>
        /// 编辑一条数据
        /// </summary>
        /// <param name="cashnumber"></param>
        /// <returns></returns>
        public JsonResult UpdateCashnumber(Cashnumber cashnumber) 
        {
            ResponseResult result = new ResponseResult();
            cashnumber.Cash_freeze = 0;
            cashnumber.Cash_UpdateTime = DateTime.Now;
            cashnumber.Cash_CreateTime = DateTime.Now;
            result.Success = _cashnumberService.Update(cashnumber);
            return Json(result);
        }

        /// <summary>
        /// 根据id获取现金帐号对象
        /// </summary>
        /// <param name="id"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public JsonResult GetCashuNumber(int id)
        {
            ResponseResult result = new ResponseResult();
            result.data = _cashnumberService.Query(a=> a.Cash_Id == id);
            result.Success = false;
            if (result.data != null) 
            {
                result.Success = true;
            }
            return Json(result);
        }

        /// <summary>
        /// 根据Id删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonResult DeleteCashNumber(int id) 
        {
            ResponseResult result = new ResponseResult();
            result = _cashnumberService.DeleteCashRecord(id);
            return Json(result);
        }

        /// <summary> 
        /// 多表删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonResult DeleteCash(int id)
        {
            ResponseResult result = new ResponseResult();
            result = _cashnumberService.DeleteCash(id);
            return Json(result);
        }

        /// <summary>
        /// 修改状态
        /// </summary>
        /// <param name="cashnumber_Record"></param>
        /// <returns></returns>
        public JsonResult UpdateState(Cashnumber_record cashnumber_Record)
        {
            ResponseResult result = new ResponseResult();
            result = _cashnumberService.UpdateState(cashnumber_Record);
            return Json(result);
        }
    }
}